#include "stdio.h"
#include <malloc.h>
#include <string.h>
#include <limits.h>
//统计星号
int countAsterisks(char *s) {
    int count = 0, left = 0, right = 0;
    while (left + right < 2 * strlen(s)) {
        for (right = left; right < strlen(s); right++) {
            if (s[right] == '|' && s[left] == '|' && right != left) {
                break;
            } else if (s[left] != '|') {
                if (s[left] == '*') {
                    count++;
                }
                left++;
                right = left - 1;
            }
        }
        for (left = right + 1; left < strlen(s); left++) {
            if (s[left] == '*') {
                count++;
            } else if (s[left] == '|') {
                right = left + 1;
                break;
            }
        }
    }
    return count;
}
//整数反转
int reverse(int x) {
    int rev = 0;
    while (x != 0) {
        if (rev > INT_MAX / 10 || rev < INT_MIN / 10)
            return 0;
        rev = rev * 10 + x % 10;
        x /= 10;
    }
    return rev;
}

//窗口滑动算法
int lengthOfLongestSubstring(char *s) {
    int len = strlen(s);
    int max = 0;
    int i = 0, j = 0;
    int *map = (int *) malloc(sizeof(int) * 128);
    memset(map, -1, sizeof(int) * 128);
    for (i = 0; i < len; i++) {
        if (map[s[i]] != -1) {
            j = j > map[s[i]] + 1 ? j : map[s[i]] + 1;
        }
        map[s[i]] = i;
        max = max > i - j + 1 ? max : i - j + 1;
    }
    return max;
}

